<?php
session_start();
if (!$_SESSION['logged_in']) {
    header('Location: login.php');
    exit;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $title = $_POST['title'];
    $content = $_POST['content'];
    $articleDir = 'articles/';
    $articleFile = $articleDir . md5($title . time()) . '.html';

    if (!is_dir($articleDir)) {
        mkdir($articleDir, 0777, true);
    }

    // 保存标题和内容
    $articleContent = '<h1>' . htmlspecialchars($title) . '</h1>' . $content;
    file_put_contents($articleFile, $articleContent);

    echo "文章已发布！<br>";
    echo '<a href="admin.php" class="button">返回后台</a>';
    echo '<meta http-equiv="refresh" content="3;url=yezix.php">';
}
?>
